﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VIKI.LINQ;
using VIKI.BLL;

namespace VIKI.Web.Home.Public
{
    public partial class Home : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            bool isLogin = false;
            //判断用户是否登录
            if (Session["UserID"] == null)
            {
                HttpCookie cookies = Request.Cookies["VikiUser"];
                if (cookies != null)
                {
                    string userId = cookies["UserId"];
                    string userName = cookies["UserName"];

                    User user = new UserBLL().FindUserByName(userName);
                    if (user != null && user.UserId.ToString() == userId)
                    {
                        Session["UserID"] = user.UserId;
                        Session["UserName"] = user.UserName;
                        isLogin = true;
                    }
                }

            }
            else { isLogin = true; }

            if (isLogin)
            {
                LoginPanel.Visible = false;
                UserInfoPanel.Visible = true;
            }
            else
            {
                LoginPanel.Visible = true;
                UserInfoPanel.Visible = false;
            }
            CurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
    }
}